home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
5_5.lha
/
5_5
/
5_5c1.c
< prev
next >
Wrap
Text File
|
1993-08-08
|
904b
|
61 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
/ print out the tree in infix format
tatic void infixprint(tree* head)
cout << "( ";
if (head)
switch (head->type)
{
case PLUS:
case DIV:
case MUL:
infixprint (head->left);
cout << chr (head->type) << " ";
infixprint (head->right);
break;
case MINUS:
if (head->right)
{
infixprint (head->left);
cout << "- ";
infixprint (head->right);
}
else
{
cout << "- ";
infixprint (head->left);
}
break;
case NUMBER:
cout << head->value;
break;
case LP:
infixprint (head->left);
break;
case RP:
case END:
default:
error ("invalid type within tree");
break;
}
else
error ("NULL node found");
cout << " ) ";
oid expr:: print()
infixprint(head);